<template>
  <div style="position: relative;">
    <el-form :inline="true" size="mini" :model="formInline" label-position="right">
      <el-form-item label="项目名称">
        <el-input class="filter-item" v-model="formInline.projectName" placeholder="请输入"></el-input>
      </el-form-item>
      <el-form-item label="业务类型">
        <el-cascader v-model="formInline.businessType"
          ref="ref_business"
          :options="businesstypeTree"
          :props="businesstProps"
          :show-all-levels="false"
          clearable
          @change="businessChange"></el-cascader>
      </el-form-item>
      <el-form-item label="评分状态">
        <el-select v-model="formInline.status" clearable placeholder="请选择">
          <el-option label="未评分" :value="0"></el-option>
          <el-option label="已评分" :value="1"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" size="mini" @click="onSubmit">搜索</el-button>
        <el-button type="warning" class="el-button--reset" icon="el-icon-refresh-right" @click="resetFromdata" size="mini"></el-button>
      </el-form-item>
    </el-form>
    <el-row>
      <el-col :span="24">
        <el-table :data="tableData" size="mini" style="width: 100%;" header-cell-class-name="table-header-gray" v-loading="isShowloading">
          <el-table-column type="index" align="center" width="55" label="序号"></el-table-column>
          <el-table-column prop="projectName" align="center" label="项目名称" show-overflow-tooltip></el-table-column>
          <el-table-column prop="businessTypeName" align="center" label="业务类型" show-overflow-tooltip></el-table-column>
          <el-table-column prop="totalScore" align="center" label="项目积分" show-overflow-tooltip></el-table-column>
          <el-table-column prop="" align="center" label="评分状态" show-overflow-tooltip>
            <template slot-scope="scope">{{scope.row.status==0?'未评分':'已评分'}}</template>
          </el-table-column>
          <el-table-column prop="scoringUserName" align="center" label="评分人" show-overflow-tooltip></el-table-column>
          <el-table-column prop="scoringDate" align="center" label="评分时间" show-overflow-tooltip></el-table-column>
          <el-table-column label="操作" align="center">
            <template slot-scope="scope">
              <el-button type="text" @click="handleInfo(scope.row)">详情</el-button>
              <el-button type="text" @click="handleEdit(scope.row)">编辑</el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-row type="flex" justify="end" style="margin-top: 10px;">
          <el-pagination
            background
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="pageNo"
            :page-size="page_size"
            :page-sizes="[10, 20, 50, 100]"
            layout="total, prev, pager, next, sizes"
            :total="total"></el-pagination>
        </el-row>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { ProjectIntegrals } from '@/api/integrals.js';
import { Businesstype } from '@/api/business.js';
export default {
  name: 'Projectintergral',
  data () {
    return {
      editDialogVisible: false,
      formInline: {
        projectName: null,
        businessType: null,
        status: null
      },
      businesstypeTree: [],
      businesstProps: {
        value: 'id',
        label: 'businessName',
        children: 'children',
        checkStrictly: true,
        emitPath: false
      },
      showDetail: {},
      showEdit: {},
      tableData: [],
      villageData: [],
      total: 0,
      page_size: 10,
      pageNo: 1,
      isShowloading: false,
      Addroptions: [],
      defaultProps: {
        children: 'nodes',
        label: 'name'
      }
    }
  },
  created () {
  },
  mounted () {
    this.loadbusinesstypeTree()
    this.loadListWidgetData()
  },
  activated: function () {
    this.loadListWidgetData()// 数据加载的方法
  },
  computed: {},
  methods: {
    /**
     * 业务类型信息表树形列表
     */
    loadbusinesstypeTree () {
      return new Promise((resolve, reject) => {
        Businesstype.tree(this).then(res => {
          this.businesstypeTree = res.data
        }).catch(e => {
          reject(e);
        });
      });
    },
    businessChange () {
      this.$refs['ref_business'].dropDownVisible = false
    },
    /**
     * 项目积分管理
     */
    loadListWidgetData () {
      let params = {
        ...this.formInline,
        size: this.page_size,
        current: this.pageNo
      }
      return new Promise((resolve, reject) => {
        ProjectIntegrals.list(this, params).then(res => {
          this.tableData = res.data.records
          this.total = res.data.total
        }).catch(e => {
          reject(e);
        });
      });
    },
    // 搜索
    onSubmit () {
      this.pageNo = 1
      this.loadListWidgetData()
    },
    // 重置
    resetFromdata () {
      this.formInline = {
        projectName: null,
        businessType: null,
        status: null
      }
      this.pageNo = 1
      this.loadListWidgetData()
    },
    // 分页导航
    handleCurrentChange (val) {
      this.pageNo = val
      this.loadListWidgetData()
    },
    handleSizeChange (val) {
      this.page_size = val
      this.loadListWidgetData()
    },
    currentChange (val) {
      this.pageNo = val
      this.loadListWidgetData()
    },
    // 查看
    handleInfo (row) {
      this.$router.push({path: '/ProjectintergralDetail', query: {projectId: row.id}})
    },
    // 编辑
    handleEdit (row) {
      this.$router.push({path: '/ProjectintergralEdit', query: {projectId: row.id}})
    }
  }
}
</script>
